package reflash;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import mahongyuan.com.studentsystem.ClassFragment;
import mahongyuan.com.studentsystem.R;

public class MyAdapter extends BaseAdapter {
    ArrayList<ApkEntity> apk_list;
    LayoutInflater inflater;

    private static ImageView image;
    private File cache;
    private static List<ApkEntity> data;//数据


    public MyAdapter(Context context, ArrayList<ApkEntity> apk_list) {
        this.apk_list = apk_list;
        this.inflater = LayoutInflater.from(context);
    }

    public void onDateChange(ArrayList<ApkEntity> apk_list) {
        this.apk_list = apk_list;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return apk_list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return apk_list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        // TODO Auto-generated method stub
        ApkEntity entity = apk_list.get(position);
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_layout, null);
            holder.name_tv = (TextView) convertView
                    .findViewById(R.id.item3_apkname);
            holder.major_tv = (TextView) convertView
                    .findViewById(R.id.item3_apkinfo);
            //holder.school_tv = (TextView) convertView
            //			.findViewById(R.id.item3_apkdes);
            holder.avatar_tv = (ImageView) convertView
                    .findViewById(R.id.item3_apkiv);
            holder.viewBtn_tv = (Button) convertView
                    .findViewById(R.id.item3_dlbtn);
            holder.id_tv = (TextView) convertView
                    .findViewById(R.id.item3_apkid);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name_tv.setText(entity.getName());
        holder.major_tv.setText(entity.getmajor_name());
        holder.id_tv.setText(entity.getId());
        //holder.school_tv.setText(entity.getschool_name());
//		String img_url = "http://" + entity.getAvatar().toString();

        final String id = entity.getId();
        holder.viewBtn_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View parentView = (View) v.getParent();
                ClassFragment.setAnimation(parentView, parent.getContext(), position, id);
                Toast.makeText(parent.getContext(), "编号为:" + id + "的删除按钮被点击了", Toast.LENGTH_SHORT).show();
            }
        });

        return convertView;
    }


    class ViewHolder {
        TextView id_tv;
        TextView name_tv;
        TextView major_tv;
        TextView school_tv;
        ImageView avatar_tv;
        Button viewBtn_tv;
    }


}
